package 洛谷;

/**
 * @author ZhuYi
 * @create 2025/4/10 11:14
 */
import java.util.Scanner;

public class 小梦的AB交换 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- != 0) {
            int n = sc.nextInt();
            String s = sc.next();
            int act = 0;
            int bct = 0;
            for (int i = 0; i < s.length(); i += 2) {
                if (s.charAt(i) == 'A')
                    act++;
            }
            System.out.println(Math.min(act, n - act));
        }
    }
}